package com.jl.sms.userdata;

import java.nio.charset.Charset;

import com.jl.card.JL;
import com.jl.util.HexUtil;

public class CodingScheme {
	
	public static boolean check(String data ,int code){
		return true;
	}
	
	public String codeToHex(String data, int code) {
		byte[] array = null;
		switch (code) {
		case JL.CODE_HEX:
			return data;
		case JL.CODE_UCS2:
			array = data.trim().getBytes(Charset.forName("UTF-16BE"));
			return HexUtil.toHexString(array);
		case JL.CODE_BIT7:
		//case JL.CODE_TOBIT7:
		case JL.CODE_ASCII:
			array = data.trim().getBytes();
			return HexUtil.toHexString(array);
		default:
			return "";
		}

	}

	public String decodeFromHex(String data, int code) {
		byte[] array  = null;
		String str = null;
		switch (code) {
		case JL.CODE_HEX:
			return data;
		case JL.CODE_UCS2:
			array = HexUtil.parseHexToByteArray(data);
			str = new String(array,Charset.forName("UTF-16BE"));
			return str;
		case JL.CODE_BIT7:
		//case JL.CODE_TOBIT7:
		case JL.CODE_ASCII:
			array = HexUtil.parseHexToByteArray(data);
			str = new String(array);
			return str;
		default:
			return "";
		}
	}
	
	

}